// JavaScript Document\

//左侧展开菜单、延时
function category(){
    var oCate=document.getElementById('categorys');
    var aLi=oCate.getElementsByTagName('li');
    var oBox=document.getElementById('catebox');
    var tools=hxsd_tools();
    var aDiv=tools.getClassName(oBox,'box');
    var show_t;//显示弹框计算器
    var hide_t;//隐藏弹框计算器
    var move_t;//鼠标从弹框移入菜单延迟用计时器
    for(var i=0; i<aLi.length; i++){
        aLi[i].index=i;
        aLi[i].onmouseover=function () {
            clearTimeout(hide_t);//清除关闭
            clearTimeout(move_t);//清除鼠标移动
            var _this=this;
            show_t=setTimeout(function(){
                oBox.style.display='block';
                for(var j=0; j<aDiv.length; j++){
                    aLi[j].className='out';
                    aDiv[j].style.display='none';
                };
                aDiv[_this.index].style.display='block';
                _this.className='out hover';
            },200);
        };
        aLi[i].onmouseout=function () {
            clearTimeout(show_t);
            clearTimeout(hide_t);
            var _this=this;
            hide_t=setTimeout(function(){
                oBox.style.display='none';
                for(var j=0; j<aDiv.length; j++){
                    aLi[j].className='out';
                    aDiv[j].style.display='none';
                };
            },200);
        };
    }
    oBox.onmouseover=function(){
        clearTimeout(hide_t);
        clearTimeout(move_t);
        this.style.display="block";
    };
    oBox.onmouseout=function(){
        var _this=this;
        move_t=setTimeout(function(){
            _this.style.display="none";
            for(var j=0; j<aDiv.length; j++){
                aLi[j].className='out';
                aDiv[j].style.display='none';
            };
        },200);
    }
}


//选项卡
function change_tab(id){
    var oFloor=document.getElementById(id);
    var oTitle=oFloor.getElementsByClassName('title')[0];
    var oNav=oTitle.getElementsByClassName('nav')[0];
    var aLi=oNav.getElementsByTagName('li');
    var aTab=oFloor.getElementsByClassName('tab');
    for(var j=0; j<aLi.length; j++){
        aLi[j].index=j;
        aLi[j].onmouseover=function(){
            for(var k=0; k<aLi.length; k++){
                aLi[k].className='';
                aTab[k].style.display='none';
            }
            this.className='hover';
            aTab[this.index].style.display='block';
        }
    }
}

//侧边栏
function sideBar(){
    var tools=hxsd_tools();
    var aFloor=document.getElementsByClassName('floor');
    var oSide=document.getElementById('side_nav');
    var inner=aFloor[0].children[0];
    var aSide=oSide.getElementsByTagName('li');
    var aFtitle=tools.getClassName(document,'floor_title');
    var wheight=document.documentElement.clientHeight;
    oSide.style.top= wheight/2-oSide.offsetHeight/2+'px';
    oSide.style.left=inner.offsetLeft-34+'px';
    var scroll_top;
    if (document.documentElement && document.documentElement.scrollTop){
        scroll_top = document.documentElement.scrollTop;
    }
    else if (document.body){
        scroll_top = document.body.scrollTop;
    };
    if(scroll_top>aFloor[0].offsetTop-wheight){
        oSide.style.display='block';
    }else{
        oSide.style.display='none';
    }
    for(var i=0; i<aFloor.length; i++){
        if(scroll_top>aFloor[i].offsetTop-wheight/2){
            for(var j=0; j<aFloor.length; j++){
                aSide[j].className='';
                aFtitle[j].className='title floor_title clear';
            }
            aSide[i].className='ac';
            aFtitle[i].className='title floor_title clear ac';
        }
    }
}

//滚动条
function windowscroll(){
    var tools=hxsd_tools();
    var aFloor=document.getElementsByClassName('floor');
    var oSide=document.getElementById('side_nav');
    var inner=aFloor[0].children[0];
    var aSide=oSide.getElementsByTagName('li');
    var aFtitle=tools.getClassName(document,'floor_title');
    var timer=null;
    for(var i=0; i<aSide.length; i++){
        aSide[i].index=i;
        aSide[i].onclick=function(){
            clearInterval(timer);
            var top=aFloor[this.index].offsetTop;
            var count=parseInt(1000/30);
            var scroll_top;
            if (document.documentElement && document.documentElement.scrollTop){
                scroll_top = document.documentElement.scrollTop;
            }
            else if (document.body){
                scroll_top = document.body.scrollTop;
            }
            var dis=top-scroll_top;
            var n=0;
            timer=setInterval(function(){
                n++;
                var a=1-n/count;
                var step=scroll_top+dis*(1-a*a*a);
                window.scrollTo(0,step);
                if(n==count){
                    clearInterval(timer);
                }
            },30);
        }
    }
}

//banner
function slide(id,hideNum){
    var slide=document.getElementById(id);
    var slideList=slide.getElementsByClassName('slideList')[0];//UL；
    var aLi=slideList.getElementsByTagName('li');
    var n=0;//第一张图片的索引
    //ul 设定宽度
    var li_w=aLi[0].offsetWidth;
    slideList.style.width=li_w*aLi.length+'px';
    //插入编号按钮
    var ol=document.createElement('ol');
    for(var i=0; i<aLi.length; i++){
        if(i==0){
            ol.innerHTML+='<li class="ac">'+(hideNum ? "" : (i+1))+'</li>';
        }else{
            ol.innerHTML+='<li>'+(hideNum ? "" : (i+1))+'</li>';
        }
    };
    slide.appendChild(ol);
    //点击数字按钮切换图片
    var aBtn=ol.children;
    function changeBtnClass(){//改变按钮样式
        for(var j=0; j<aBtn.length; j++){
            aBtn[j].className='';
        };
        aBtn[n].className='ac';
    };
    var auto_timer=null;
    function auto_play() {
         clearTimeout(hover_timer);
         clearTimeout(auto_timer);
         var tools=hxsd_tools();
         auto_timer=setInterval(function () {
             n++;
             if(n>aLi.length-1)n=0;
             changeBtnClass();
             tools.hxsd_move(slideList, {"left": -(parseInt(slide.offsetWidth) * n)});
         },2000)
    }
    auto_play();
    var hover_timer=null;
    for(var i=0; i<aBtn.length; i++){
        aBtn[i].index=i;//发牌照
        aBtn[i].onclick=function(){
            n=this.index;
            changeBtnClass()
            var tools=hxsd_tools();
            tools.hxsd_move(slideList,{'left':-(li_w*n)});
        };
        aBtn[i].onmouseover=function (ev) {
            var oEv=ev||window.event;
            oEv.cancelBubble=true;
            var _this=this
            clearTimeout(hover_timer);
            clearInterval(auto_timer);
            hover_timer=setTimeout(function(){
                n=_this.index;
                changeBtnClass()
                var tools=hxsd_tools();
                tools.hxsd_move(slideList,{'left':-(li_w*n)});
            },200)
        }
        aBtn[i].onmouseout=function (ev) {
            var oEv=ev||window.event;
            oEv.cancelBubble=true;
            clearTimeout(hover_timer);
            clearInterval(auto_timer);
            auto_play();
        }
    };
    //点击前后按钮，切换图片
    var pBtn=slide.getElementsByClassName('prev')[0];
    var nBtn=slide.getElementsByClassName('next')[0];

    pBtn.onclick=function(){
        n--;
        if(n<0)n=aLi.length-1;
        var tools=hxsd_tools();
        tools.hxsd_move(slideList,{'left':-(li_w*n)});
        changeBtnClass();
    };

    nBtn.onclick=function(){
        n++;
        if(n>aLi.length-1)n=0;
        var tools=hxsd_tools();
        tools.hxsd_move(slideList,{'left':-(li_w*n)});
        changeBtnClass();
    }

    slide.onmouseover=function () {
        clearTimeout(hover_timer);
        clearInterval(auto_timer);
		pBtn.style.display='block';
		nBtn.style.display='block';
    }
    slide.onmouseout=function () {
        auto_play();
		pBtn.style.display='none';
		nBtn.style.display='none';
    }
};
function icon_slider(id) {
    var num=0;
    //icon
    function slide_icon(){
        var oUl=document.getElementById('slide_icon');
        var tab=document.getElementById('slide_main');
        var showtab = null;
        var aLi=oUl.children;
        var tools=hxsd_tools();
        var oCls=document.getElementById('afterclose');
        for(var i=0; i<4; i++){
            aLi[i].index=i;
            aLi[i].onmouseover=function (ev) {
                var oEv=ev||event;
                num=this.index;
                if(this.index==3){
                    if(this.getAttribute('date-closed')==0){
                        return;
                    }
                }
                clearTimeout(showtab);
                var n=0;
                showtab = setTimeout(function () {
                    tab.style.display='block';
                    tools.hxsd_move(tab,{'top':0},500,function () {
                        var tools=hxsd_tools();
                        var tab=document.getElementById(id);
                        var tabItem=tools.getClassName(tab,'tabItem');
                        var tabList=tab.getElementsByTagName('ul')[0];
                        var oLi=tabList.getElementsByTagName('li');
                        var oClose=tools.getClassName(tab,'closeicon')[0];
                        var oCls=document.getElementById('afterclose');
                        for(i=0;i<oLi.length;i++){
                            tabItem[i].style.display="none";
                            oLi[i].className="";
                        };
                        oLi[num].className="active";
                        tabItem[num].style.display="block";
                    })
                },500)
                console.log(this.className);
            }
            aLi[i].onmouseout=function (ev) {
                var oEv=ev||event;
                var oEl=oEv.relatedTarget||oEv.toElement;
                if(oEl!=this && oEl!=this.children[0]){
                    oCls.setAttribute('date-closed',1);
                };
                clearTimeout(showtab);
            }
        }
    }

//iconmain翻页
    function slide_main (id){
        var tools=hxsd_tools();
        var tab=document.getElementById(id);
        var tabItem=tools.getClassName(tab,'tabItem');
        var tabList=tab.getElementsByTagName('ul')[0];
        var oLi=tabList.getElementsByTagName('li');
        var oClose=tools.getClassName(tab,'closeicon')[0];
        var oCls=document.getElementById('afterclose');
        var timer;
        var n=0;
        function move(){
            for(i=0;i<oLi.length;i++){
                tabItem[i].style.display="none";
                oLi[i].className="";
            };
            this.className="active";
            tabItem[this.index].style.display="block";
            n=this.index;
        };
        for(j=0;j<oLi.length;j++){
            oLi[j].index=j;
            oLi[j].onmouseover=move;
        };
        oClose.onclick=function (ev) {
            var oEv=ev||event;
            tools.hxsd_move(tab,{'top':250},500)
            oCls.setAttribute('date-closed',0);
        }
    };
    slide_icon();
    slide_main(id);
}




function isParent(parent,obj){
    while(obj){
        if(obj==parent)return true;
        obj=obj.parentNode;
    }
    return false;
}